from app.util.annotation_util import annotate, ClassInfo
from app.view.base_view import View


@annotate(ClassInfo(name="Music", category="muse", plug=False))
class MusicView(View):
    def __init__(self, parent, controller):
        super().__init__(parent, controller)
    #     # 音频播放相关配置
    #     self.p = pyaudio.PyAudio()
    #     self.stream = None
    #     self.audio_file = None
    #     self.audio_format = pyaudio.paInt16
    #     self.channels = 2
    #     self.rate = 44100
    #     self.chunk = 1024
    #     self.is_playing = False
    #     self.is_paused = False
    #     self.current_position = 0
    #     self.total_frames = 0
    #     self.audio_data = None
    #     self.play_thread = None
    #     self.stop_event = threading.Event()
    #
    #     # 播放列表相关变量
    #     self.playlist = []
    #     self.current_index = -1
    #     self.is_shuffle = False
    #     self.is_repeat = False
    #
    #     # 歌词相关变量
    #     self.lyrics = []
    #     self.lyric_index = -1
    #
    #     # 创建主界面
    #     self.create_main_ui()
    #
    #     # 绑定事件
    #     # self.protocol("WM_DELETE_WINDOW", self.on_close)
    #
    # def create_main_ui(self):
    #     """创建主界面"""
    #     # 创建主框架
    #     self.main_frame = ttk.Frame(self, padding=10)
    #     self.main_frame.pack(fill=BOTH, expand=True)
    #
    #     # 创建顶部控制栏
    #     self.create_control_bar()
    #
    #     # 创建分隔符
    #     ttk.Separator(self.main_frame, orient=HORIZONTAL).pack(fill=X, pady=5)
    #
    #     # 主内容区域（左侧播放区+右侧列表）
    #     content_frame = ttk.Frame(self.main_frame)
    #     content_frame.pack(fill=BOTH, expand=True, pady=5)
    #
    #     # 左侧播放区域（使用Notebook）
    #     left_frame = ttk.Frame(content_frame)
    #     left_frame.pack(side=LEFT, fill=BOTH, expand=True, padx=5)
    #
    #     self.notebook = ttk.Notebook(left_frame)
    #     self.notebook.pack(fill=BOTH, expand=True)
    #
    #     # 创建播放页面
    #     self.play_frame = ttk.Frame(self.notebook)
    #     self.notebook.add(self.play_frame, text="播放")
    #     self.create_play_page()
    #
    #     # 创建频谱页面
    #     self.spectrum_frame = ttk.Frame(self.notebook)
    #     self.notebook.add(self.spectrum_frame, text="频谱")
    #     self.create_spectrum_page()
    #
    #     # 创建歌词页面
    #     self.lyrics_frame = ttk.Frame(self.notebook)
    #     self.notebook.add(self.lyrics_frame, text="歌词")
    #     self.create_lyrics_page()
    #
    #     # 右侧播放列表
    #     right_frame = ttk.Frame(content_frame)
    #     right_frame.pack(side=RIGHT, fill=BOTH, expand=True, padx=5)
    #     self.create_playlist_page(right_frame)
    #
    #     # 创建分隔符
    #     ttk.Separator(self.main_frame, orient=HORIZONTAL).pack(fill=X, pady=5)
    #
    #     # 底部播放控制栏
    #     self.create_playback_controls()
    #
    # def create_control_bar(self):
    #     """创建顶部控制栏"""
    #     control_bar = ttk.Frame(self.main_frame)
    #     control_bar.pack(fill=X, pady=5)
    #
    #     # 选择文件夹按钮
    #     ttk.Button(
    #         control_bar,
    #         text="选择音乐文件夹",
    #         command=self.select_music_folder
    #     ).pack(side=LEFT, padx=5)
    #
    #     # 清除播放列表按钮
    #     ttk.Button(
    #         control_bar,
    #         text="清除播放列表",
    #         command=self.clear_playlist
    #     ).pack(side=LEFT, padx=5)
    #
    #     # 分隔符
    #     ttk.Separator(control_bar, orient=VERTICAL).pack(side=LEFT, padx=10, fill=Y)
    #
    #     # 模式控制
    #     self.shuffle_var = tk.BooleanVar(value=self.is_shuffle)
    #     ttk.Checkbutton(
    #         control_bar,
    #         text="随机播放",
    #         variable=self.shuffle_var,
    #         command=self.toggle_shuffle
    #     ).pack(side=LEFT, padx=5)
    #
    #     self.repeat_var = tk.BooleanVar(value=self.is_repeat)
    #     ttk.Checkbutton(
    #         control_bar,
    #         text="循环播放",
    #         variable=self.repeat_var,
    #         command=self.toggle_repeat
    #     ).pack(side=LEFT, padx=5)
    #
    # def create_play_page(self):
    #     """创建播放页面"""
    #     # 歌曲信息区域
    #     info_frame = ttk.LabelFrame(self.play_frame, text="歌曲信息", padding=10)
    #     info_frame.pack(fill=X, pady=10, padx=10)
    #
    #     # 歌曲封面
    #     self.album_cover = ttk.Label(info_frame, text="封面", width=30, bootstyle=SECONDARY)
    #     self.album_cover.pack(side=LEFT, padx=10)
    #
    #     # 歌曲详情
    #     details_frame = ttk.Frame(info_frame)
    #     details_frame.pack(side=LEFT, fill=BOTH, expand=True, padx=10)
    #
    #     self.song_title = ttk.Label(details_frame, text="歌曲标题", font=("Arial", 16, "bold"))
    #     self.song_title.pack(anchor=W, pady=5)
    #
    #     self.song_artist = ttk.Label(details_frame, text="艺术家", font=("Arial", 12))
    #     self.song_artist.pack(anchor=W, pady=2)
    #
    #     self.song_album = ttk.Label(details_frame, text="专辑", font=("Arial", 12))
    #     self.song_album.pack(anchor=W, pady=2)
    #
    #     # 进度条
    #     progress_frame = ttk.Frame(self.play_frame)
    #     progress_frame.pack(fill=X, pady=10, padx=10)
    #
    #     self.time_label = ttk.Label(progress_frame, text="00:00")
    #     self.time_label.pack(side=LEFT)
    #
    #     self.progress_var = tk.DoubleVar()
    #     self.progress_bar = ttk.Scale(
    #         progress_frame,
    #         variable=self.progress_var,
    #         from_=0,
    #         to=100,
    #         orient=HORIZONTAL,
    #         command=self.set_position
    #     )
    #     self.progress_bar.pack(side=LEFT, fill=X, expand=True, padx=10)
    #
    #     self.total_time_label = ttk.Label(progress_frame, text="00:00")
    #     self.total_time_label.pack(side=LEFT)
    #
    # def create_playlist_page(self, parent):
    #     """创建播放列表页面"""
    #     # 播放列表区域
    #     list_frame = ttk.LabelFrame(parent, text="播放列表", padding=10)
    #     list_frame.pack(fill=BOTH, expand=True)
    #
    #     # 播放列表
    #     self.playlist_box = tk.Listbox(
    #         list_frame,
    #         selectmode=SINGLE,
    #         # bg=self.cget("bg"),
    #         # fg=self.cget("fg"),
    #         selectbackground=ttk.Style().lookup("TButton", "background"),
    #         selectforeground=ttk.Style().lookup("TButton", "foreground")
    #     )
    #     self.playlist_box.pack(fill=BOTH, expand=True)
    #
    #     # 添加滚动条
    #     scrollbar = ttk.Scrollbar(
    #         list_frame,
    #         orient=VERTICAL,
    #         command=self.playlist_box.yview
    #     )
    #     scrollbar.pack(side=RIGHT, fill=Y)
    #     self.playlist_box.config(yscrollcommand=scrollbar.set)
    #
    #     self.playlist_box.bind('<<ListboxSelect>>', self.on_playlist_select)
    #     self.playlist_box.bind('<Double-1>', self.on_playlist_double_click)
    #
    # def create_spectrum_page(self):
    #     """创建频谱页面"""
    #     spectrum_frame = ttk.LabelFrame(self.spectrum_frame, text="音频频谱", padding=10)
    #     spectrum_frame.pack(fill=BOTH, expand=True, pady=10, padx=10)
    #
    #     # 创建频谱图
    #     self.fig = Figure(figsize=(6, 4), dpi=100)
    #     self.ax = self.fig.add_subplot(111)
    #     self.canvas = FigureCanvasTkAgg(self.fig, master=spectrum_frame)
    #     self.canvas.get_tk_widget().pack(fill=BOTH, expand=True)
    #
    #     # 初始化频谱图
    #     self.ax.set_title("音频频谱")
    #     self.ax.set_xlabel("频率 (Hz)")
    #     self.ax.set_ylabel("振幅")
    #     self.canvas.draw()
    #
    #     # 频谱数据
    #     self.spectrum_data = np.zeros(self.chunk)
    #
    #     # 启动频谱更新线程
    #     self.update_spectrum_thread = threading.Thread(target=self.update_spectrum, daemon=True)
    #     self.update_spectrum_thread.start()
    #
    # def create_lyrics_page(self):
    #     """创建歌词页面"""
    #     lyrics_frame = ttk.LabelFrame(self.lyrics_frame, text="歌词", padding=10)
    #     lyrics_frame.pack(fill=BOTH, expand=True, pady=10, padx=10)
    #
    #     self.lyrics_text = scrolledtext.ScrolledText(
    #         lyrics_frame,
    #         wrap=tk.WORD,
    #         font=("SimHei", 12)
    #     )
    #     self.lyrics_text.pack(fill=BOTH, expand=True)
    #     self.lyrics_text.config(state=DISABLED)
    #     self.lyrics_text.tag_config("highlight", background="yellow", foreground="black")
    #
    # def create_playback_controls(self):
    #     """创建底部播放控制栏"""
    #     control_frame = ttk.LabelFrame(self.main_frame, text="播放控制", padding=10)
    #     control_frame.pack(fill=X, pady=10)
    #
    #     # 音量控制
    #     ttk.Label(control_frame, text="音量:").pack(side=LEFT, padx=5)
    #     self.volume_var = tk.DoubleVar(value=80)
    #     self.volume_scale = ttk.Scale(
    #         control_frame,
    #         variable=self.volume_var,
    #         from_=0,
    #         to=100,
    #         orient=HORIZONTAL,
    #         command=self.set_volume
    #     )
    #     self.volume_scale.pack(side=LEFT, fill=X, expand=True, padx=5)
    #
    #     # 播放控制按钮
    #     button_frame = ttk.Frame(control_frame)
    #     button_frame.pack(side=LEFT, padx=20)
    #
    #     ttk.Button(
    #         button_frame,
    #         text="上一首",
    #         command=self.play_previous,
    #         bootstyle=PRIMARY
    #     ).pack(side=LEFT, padx=10)
    #
    #     self.play_pause_btn = ttk.Button(
    #         button_frame,
    #         text="播放",
    #         command=self.toggle_play_pause,
    #         bootstyle=SUCCESS
    #     )
    #     self.play_pause_btn.pack(side=LEFT, padx=10)
    #
    #     ttk.Button(
    #         button_frame,
    #         text="下一首",
    #         command=self.play_next,
    #         bootstyle=PRIMARY
    #     ).pack(side=LEFT, padx=10)
    #
    #     # 音量初始值
    #     self.volume = 0.8
    #
    # def select_music_folder(self):
    #     """选择音乐文件夹并加载音乐文件"""
    #     folder = filedialog.askdirectory()
    #     if folder:
    #         # 扫描文件夹中的音乐文件
    #         music_extensions = ['.mp3', '.wav']
    #         for root, dirs, files in os.walk(folder):
    #             for file in files:
    #                 if any(file.lower().endswith(ext) for ext in music_extensions):
    #                     file_path = os.path.join(root, file)
    #                     if file_path not in self.playlist:
    #                         self.playlist.append(file_path)
    #                         # 获取歌曲信息
    #                         try:
    #                             if file.lower().endswith('.mp3'):
    #                                 audio = EasyID3(file_path)
    #                                 title = audio.get('title', [os.path.basename(file_path)])[0]
    #                                 artist = audio.get('artist', ['未知艺术家'])[0]
    #                                 display_text = f"{title} - {artist}"
    #                             else:
    #                                 display_text = os.path.basename(file_path)
    #                         except:
    #                             display_text = os.path.basename(file_path)
    #
    #                         self.playlist_box.insert(END, display_text)
    #
    # def clear_playlist(self):
    #     """清除播放列表"""
    #     self.stop_playback()
    #     self.playlist.clear()
    #     self.playlist_box.delete(0, END)
    #     self.current_index = -1
    #     self.update_song_info(None)
    #
    # def on_playlist_select(self, event):
    #     """播放列表选择事件"""
    #     selection = self.playlist_box.curselection()
    #     if selection:
    #         self.current_index = selection[0]
    #
    # def on_playlist_double_click(self, event):
    #     """双击播放列表项播放音乐"""
    #     selection = self.playlist_box.curselection()
    #     if selection:
    #         self.current_index = selection[0]
    #         self.play_selected()
    #
    # def play_selected(self):
    #     """播放选中的歌曲"""
    #     if 0 <= self.current_index < len(self.playlist):
    #         song_path = self.playlist[self.current_index]
    #         self.load_and_play_song(song_path)
    #
    # def load_and_play_song(self, song_path):
    #     """加载并播放歌曲"""
    #     # 停止当前播放
    #     self.stop_playback()
    #
    #     try:
    #         # 加载歌曲信息
    #         self.update_song_info(song_path)
    #         self.load_lyrics(song_path)
    #
    #         # 根据文件类型处理
    #         if song_path.lower().endswith('.wav'):
    #             self.load_wav_file(song_path)
    #         elif song_path.lower().endswith('.mp3'):
    #             self.load_mp3_file(song_path)
    #         else:
    #             raise Exception(f"不支持的文件格式: {song_path}")
    #
    #         # 开始播放
    #         self.start_playback()
    #
    #     except Exception as e:
    #         print(f"播放错误: {e}")
    #         messagebox.showerror("播放错误", f"无法播放歌曲: {str(e)}")
    #
    # def load_wav_file(self, file_path):
    #     """加载WAV文件"""
    #     self.audio_file = wave.open(file_path, 'rb')
    #     self.audio_format = pyaudio.paInt16
    #     self.channels = self.audio_file.getnchannels()
    #     self.rate = self.audio_file.getframerate()
    #     self.total_frames = self.audio_file.getnframes()
    #     self.current_position = 0
    #
    #     # 计算总时长(秒)
    #     self.total_duration = self.total_frames / self.rate
    #     self.total_time_label.config(text=self.format_time(self.total_duration))
    #
    # def load_mp3_file(self, file_path):
    #     """加载MP3文件"""
    #     # 使用mutagen获取MP3信息
    #     mp3 = MP3(file_path)
    #     self.rate = mp3.info.sample_rate
    #     self.channels = mp3.info.channels
    #     self.total_duration = mp3.info.length
    #
    #     # 计算总帧数
    #     self.total_frames = int(self.rate * self.total_duration)
    #     self.current_position = 0
    #
    #     self.total_time_label.config(text=self.format_time(self.total_duration))
    #
    #     # 保存文件路径供播放时使用
    #     self.mp3_file_path = file_path
    #
    # def start_playback(self):
    #     """开始播放音频"""
    #     # 重置停止事件
    #     self.stop_event.clear()
    #
    #     # 创建音频流
    #     self.stream = self.p.open(
    #         format=self.audio_format,
    #         channels=self.channels,
    #         rate=self.rate,
    #         output=True,
    #         frames_per_buffer=self.chunk,
    #         stream_callback=self.audio_callback
    #     )
    #
    #     # 更新状态
    #     self.is_playing = True
    #     self.is_paused = False
    #     self.play_pause_btn.config(text="暂停")
    #
    #     # 高亮显示当前播放项
    #     self.playlist_box.selection_clear(0, END)
    #     self.playlist_box.selection_set(self.current_index)
    #     self.playlist_box.see(self.current_index)
    #
    #     # 启动进度更新线程
    #     self.progress_thread = threading.Thread(target=self.update_progress, daemon=True)
    #     self.progress_thread.start()
    #
    # def audio_callback(self, in_data, frame_count, time_info, status):
    #     """音频回调函数"""
    #     if self.stop_event.is_set():
    #         return (None, pyaudio.paComplete)
    #
    #     if self.is_paused:
    #         return (b'\x00' * frame_count * self.channels * 2, pyaudio.paContinue)
    #
    #     data = b''
    #     try:
    #         if self.audio_file:  # WAV文件
    #             data = self.audio_file.readframes(frame_count)
    #             self.current_position += frame_count
    #         else:  # MP3文件，这里使用简单的方式，实际项目中可能需要更复杂的解码
    #             # 注意：这只是一个示例，实际的MP3解码需要更复杂的处理
    #             pass
    #
    #         # 应用音量
    #         if self.volume != 1.0 and data:
    #             # 将字节数据转换为numpy数组
    #             fmt = f"{len(data) // 2}h"
    #             audio_data = np.array(struct.unpack(fmt, data), dtype=np.int16)
    #             # 应用音量
    #             audio_data = (audio_data * self.volume).astype(np.int16)
    #             # 转换回字节
    #             data = struct.pack(fmt, *audio_data)
    #
    #         # 保存频谱数据
    #         if len(data) >= self.chunk * 2:  # 确保有足够的数据
    #             fmt = f"{self.chunk}h"
    #             self.spectrum_data = np.array(struct.unpack(fmt, data[:self.chunk * 2]), dtype=np.int16)
    #
    #         # 检查是否播放完毕
    #         if len(data) < frame_count * self.channels * 2:
    #             # 播放完毕
    #             self.after(0, self.handle_playback_complete)
    #             return (data, pyaudio.paComplete)
    #
    #     except Exception as e:
    #         print(f"音频回调错误: {e}")
    #         return (None, pyaudio.paComplete)
    #
    #     return (data, pyaudio.paContinue)
    #
    # def handle_playback_complete(self):
    #     """处理播放完成事件"""
    #     self.is_playing = False
    #     self.play_pause_btn.config(text="播放")
    #
    #     if self.is_repeat:
    #         # 单曲循环
    #         self.play_selected()
    #     elif self.current_index < len(self.playlist) - 1 or self.is_shuffle:
    #         # 播放下一首
    #         self.play_next()
    #
    # def toggle_play_pause(self):
    #     """切换播放/暂停状态"""
    #     if not self.playlist:
    #         return
    #
    #     if self.is_playing:
    #         if self.is_paused:
    #             # 从暂停状态恢复播放
    #             self.is_paused = False
    #             self.play_pause_btn.config(text="暂停")
    #         else:
    #             # 暂停播放
    #             self.is_paused = True
    #             self.play_pause_btn.config(text="播放")
    #     else:
    #         # 如果当前没有播放的歌曲，播放选中的或第一首
    #         if self.current_index == -1 and self.playlist:
    #             self.current_index = 0
    #         self.play_selected()
    #
    # def stop_playback(self):
    #     """停止播放"""
    #     if self.is_playing or self.is_paused:
    #         self.stop_event.set()
    #         if self.stream:
    #             self.stream.stop_stream()
    #             self.stream.close()
    #             self.stream = None
    #
    #         if self.audio_file:
    #             self.audio_file.close()
    #             self.audio_file = None
    #
    #         self.is_playing = False
    #         self.is_paused = False
    #         self.play_pause_btn.config(text="播放")
    #         self.progress_var.set(0)
    #         self.time_label.config(text="00:00")
    #
    # def play_previous(self):
    #     """播放上一首"""
    #     if not self.playlist:
    #         return
    #
    #     if self.is_shuffle:
    #         # 随机播放模式下，随机选择一首不同的歌曲
    #         if len(self.playlist) > 1:
    #             new_index = self.current_index
    #             while new_index == self.current_index:
    #                 new_index = random.randint(0, len(self.playlist) - 1)
    #             self.current_index = new_index
    #             self.play_selected()
    #     else:
    #         # 顺序播放模式下，播放上一首
    #         self.current_index = (self.current_index - 1) % len(self.playlist)
    #         self.play_selected()
    #
    # def play_next(self):
    #     """播放下一首"""
    #     if not self.playlist:
    #         return
    #
    #     if self.is_shuffle:
    #         # 随机播放模式下，随机选择一首不同的歌曲
    #         if len(self.playlist) > 1:
    #             new_index = self.current_index
    #             while new_index == self.current_index:
    #                 new_index = random.randint(0, len(self.playlist) - 1)
    #             self.current_index = new_index
    #             self.play_selected()
    #     else:
    #         # 顺序播放模式下，播放下一首
    #         self.current_index = (self.current_index + 1) % len(self.playlist)
    #         self.play_selected()
    #
    # def toggle_shuffle(self):
    #     """切换随机播放模式"""
    #     self.is_shuffle = self.shuffle_var.get()
    #
    # def toggle_repeat(self):
    #     """切换循环播放模式"""
    #     self.is_repeat = self.repeat_var.get()
    #
    # def set_volume(self, value):
    #     """设置音量"""
    #     self.volume = float(value) / 100
    #
    # def set_position(self, value):
    #     """设置播放位置"""
    #     if not self.is_playing or not self.total_frames:
    #         return
    #
    #     try:
    #         # 计算目标位置
    #         position_percent = float(value) / 100.0
    #         target_frame = int(self.total_frames * position_percent)
    #
    #         # 停止当前播放
    #         was_playing = self.is_playing
    #         self.stop_playback()
    #
    #         # 重新打开文件并定位到目标位置
    #         song_path = self.playlist[self.current_index]
    #         if song_path.lower().endswith('.wav'):
    #             self.audio_file = wave.open(song_path, 'rb')
    #             self.audio_file.setpos(target_frame)
    #             self.current_position = target_frame
    #         elif song_path.lower().endswith('.mp3'):
    #             # MP3定位比较复杂，这里简化处理
    #             self.current_position = target_frame
    #
    #         # 如果之前在播放，继续播放
    #         if was_playing:
    #             self.start_playback()
    #
    #     except Exception as e:
    #         print(f"设置播放位置错误: {e}")
    #
    # def format_time(self, seconds):
    #     """格式化时间（秒 -> mm:ss）"""
    #     minutes = int(seconds // 60)
    #     seconds = int(seconds % 60)
    #     return f"{minutes:02d}:{seconds:02d}"
    #
    # def update_progress(self):
    #     """更新播放进度"""
    #     while self.is_playing and not self.stop_event.is_set():
    #         try:
    #             if self.total_frames > 0:
    #                 # 计算当前进度百分比
    #                 progress = (self.current_position / self.total_frames) * 100
    #                 self.progress_var.set(progress)
    #
    #                 # 计算当前播放时间
    #                 current_time = self.current_position / self.rate
    #                 self.time_label.config(text=self.format_time(current_time))
    #
    #                 # 更新歌词显示
    #                 self.after(0, self.update_lyrics_display)
    #         except Exception as e:
    #             print(f"更新进度错误: {e}")
    #
    #         time.sleep(0.1)
    #
    # def update_spectrum(self):
    #     """更新频谱显示"""
    #     while True:
    #         if self.is_playing and not self.is_paused and not self.stop_event.is_set():
    #             try:
    #                 # 清除之前的图像
    #                 self.ax.clear()
    #
    #                 # 计算频谱
    #                 if len(self.spectrum_data) > 0:
    #                     # 计算FFT
    #                     fft_data = np.fft.fft(self.spectrum_data)
    #                     fft_mag = np.abs(fft_data)[:len(fft_data) // 2]
    #                     frequencies = np.fft.fftfreq(len(self.spectrum_data), 1.0 / self.rate)[:len(fft_data) // 2]
    #
    #                     # 绘制频谱图
    #                     self.ax.plot(frequencies, fft_mag)
    #                     self.ax.set_xlim(0, 10000)  # 限制频率范围，使图像更清晰
    #
    #                 self.ax.set_title("音频频谱")
    #                 self.ax.set_xlabel("频率 (Hz)")
    #                 self.ax.set_ylabel("振幅")
    #
    #                 # 更新画布
    #                 self.canvas.draw()
    #             except Exception as e:
    #                 print(f"频谱更新错误: {e}")
    #
    #         # 每0.1秒更新一次频谱
    #         time.sleep(0.1)
    #
    # def update_song_info(self, song_path):
    #     """更新歌曲信息显示"""
    #     if not song_path:
    #         self.song_title.config(text="歌曲标题")
    #         self.song_artist.config(text="艺术家")
    #         self.song_album.config(text="专辑")
    #         return
    #
    #     try:
    #         if song_path.lower().endswith('.mp3'):
    #             audio = EasyID3(song_path)
    #             title = audio.get('title', [os.path.basename(song_path)])[0]
    #             artist = audio.get('artist', ['未知艺术家'])[0]
    #             album = audio.get('album', ['未知专辑'])[0]
    #
    #             self.song_title.config(text=title)
    #             self.song_artist.config(text=artist)
    #             self.song_album.config(text=album)
    #         else:
    #             self.song_title.config(text=os.path.basename(song_path))
    #             self.song_artist.config(text="未知艺术家")
    #             self.song_album.config(text="未知专辑")
    #
    #     except Exception as e:
    #         print(f"更新歌曲信息错误: {e}")
    #         self.song_title.config(text=os.path.basename(song_path))
    #         self.song_artist.config(text="未知艺术家")
    #         self.song_album.config(text="未知专辑")
    #
    # def load_lyrics(self, song_path):
    #     """加载歌曲歌词"""
    #     self.lyrics = []
    #     self.lyric_index = -1
    #
    #     # 尝试从同名lrc文件中读取歌词
    #     lrc_path = os.path.splitext(song_path)[0] + '.lrc'
    #     if os.path.exists(lrc_path):
    #         try:
    #             with open(lrc_path, 'r', encoding='utf-8') as f:
    #                 lyrics_text = f.read()
    #                 self.parse_lyrics(lyrics_text)
    #                 return
    #         except Exception as e:
    #             print(f"读取LRC文件错误: {e}")
    #
    #     # 如果没有找到歌词
    #     self.lyrics_text.config(state=NORMAL)
    #     self.lyrics_text.delete(1.0, END)
    #     self.lyrics_text.insert(END, "未找到歌词")
    #     self.lyrics_text.config(state=DISABLED)
    #
    # def parse_lyrics(self, lyrics_text):
    #     """解析歌词文本"""
    #     # 正则表达式匹配歌词时间标签
    #     pattern = r'\[(\d+:\d+\.\d+)\](.*)'
    #     matches = re.findall(pattern, lyrics_text)
    #
    #     self.lyrics = []
    #     for time_str, lyric in matches:
    #         # 转换时间格式 [mm:ss.ms] 为秒
    #         minutes, seconds = time_str.split(':')
    #         total_seconds = int(minutes) * 60 + float(seconds)
    #         self.lyrics.append((total_seconds, lyric.strip()))
    #
    #     # 按时间排序
    #     self.lyrics.sort(key=lambda x: x[0])
    #
    #     # 显示所有歌词
    #     self.lyrics_text.config(state=NORMAL)
    #     self.lyrics_text.delete(1.0, END)
    #     for time_stamp, lyric in self.lyrics:
    #         self.lyrics_text.insert(END, f"{lyric}\n")
    #     self.lyrics_text.config(state=DISABLED)
    #
    # def update_lyrics_display(self):
    #     """更新歌词显示，高亮当前歌词"""
    #     if not self.lyrics or not self.total_frames:
    #         return
    #
    #     # 当前播放时间（秒）
    #     current_time = self.current_position / self.rate
    #
    #     # 找到当前应该显示的歌词
    #     new_index = self.lyric_index
    #     for i, (time_stamp, lyric) in enumerate(self.lyrics):
    #         if time_stamp <= current_time + 0.5:  # 微小的提前量
    #             new_index = i
    #         else:
    #             break
    #
    #     if new_index != self.lyric_index:
    #         self.lyric_index = new_index
    #
    #         # 高亮当前歌词
    #         self.lyrics_text.config(state=NORMAL)
    #         # 清除之前的高亮
    #         self.lyrics_text.tag_remove("highlight", 1.0, END)
    #         # 添加新的高亮
    #         line = new_index + 1
    #         self.lyrics_text.tag_add("highlight", f"{line}.0", f"{line}.end")
    #         # 滚动到当前歌词
    #         self.lyrics_text.see(f"{line}.0")
    #         self.lyrics_text.config(state=DISABLED)
    #
    # def on_close(self):
    #     """关闭窗口时的处理"""
    #     self.stop_playback()
    #     self.stop_event.set()
    #     self.p.terminate()
    #     self.destroy()
        
    def create_widgets(self):
        pass
